package com.suqiu.qqrobot.service.impl;


import com.suqiu.qqrobot.common.log.annotation.LogMgr;
import com.suqiu.qqrobot.model.Message;
import com.suqiu.qqrobot.model.TextMessage;
import com.unfbx.chatgpt.OpenAiClient;
import com.unfbx.chatgpt.entity.whisper.Transcriptions;
import com.unfbx.chatgpt.entity.whisper.WhisperResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.io.File;

/**
 * 语音转文字功能
 */
@LogMgr
@RequiredArgsConstructor
@Service("openAiTranscriptionsModelService")
public class OpenAiTranscriptionsModelService implements OpenAiChatService<File, String> {

    private final OpenAiClient openAiClient;

    @Override
    public Message<String> chat(String sessionId, File question) {
        Transcriptions transcriptions = Transcriptions.builder().language("en").build();
        WhisperResponse whisperResponse = openAiClient.speechToTextTranscriptions(question, transcriptions);
        Message<String> message = new TextMessage();
        message.setMessage(whisperResponse.getText());
        return message;
    }
}
